package cn.edu.cxcyzx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.edu.cxcyzx.algorithm.CalProgress_project;
import cn.edu.cxcyzx.entity.ApplyProject;
import cn.edu.cxcyzx.entity.CheckProject;
import cn.edu.cxcyzx.entity.CheckProjectPOJO;
import cn.edu.cxcyzx.entity.Progress_project;
import cn.edu.cxcyzx.entity.Project;
import cn.edu.cxcyzx.service.CheckProjectService;
import cn.edu.cxcyzx.supervisor.DaoFit;

@Service("CheckProjectService")
public class CheckProjectServiceImpl implements CheckProjectService {
	
	@Resource
	public DaoFit daoFit;
	
	@Override
	public void insert_checkProject(CheckProject checkProject) {
		// TODO Auto-generated method stub
		if(checkProject!=null){
			daoFit.getCheckProjectDao().insert_checkProject(checkProject);
		}
	}

	@Override
	public CheckProject getCheckProject(int projectId) {
		// TODO Auto-generated method stub
		
		return daoFit.getCheckProjectDao().getCheckProject(projectId);
	}

	@Override
	public List<CheckProjectPOJO> getAllPro() {
		// TODO Auto-generated method stub
		return daoFit.getCheckProjectDao().getAllPro();
	}

	@Override
	public int getNum_checkPro() {
		// TODO Auto-generated method stub
		
		return daoFit.getCheckProjectDao().getNum_checkPro();
	}

	@Override
	public void success_checkPro(CheckProject checkProject) {
		// TODO Auto-generated method stub
		if(checkProject!=null){
			daoFit.getCheckProjectDao().success_checkPro(checkProject);
		}
	}

	@Override
	public void fail_checkPro(String failCheckInfo, int projectId) {
		// TODO Auto-generated method stub
		daoFit.getCheckProjectDao().fail_checkPro(failCheckInfo, projectId);
	}

	@Override
	public void setCheckResult(CheckProject checkProject) {
		// TODO Auto-generated method stub
		if(checkProject.getRebackRoom()==1){
			//回收房间
			Project pro=daoFit.getProjectDao().getProjectBy_projectId(checkProject.getProjectId());
			daoFit.getRoomDao().addRest(pro.getRoomId(), pro.getMemberNum());
		}
		//更新check_project表
		daoFit.getCheckProjectDao().update_result(checkProject);
		//更新apply_project
		daoFit.getApplyProjectDao().updateStatus(new ApplyProject(checkProject.getProjectId(),3));
		//更新project表
		daoFit.getProjectDao().update_projectStatus(checkProject.getProjectId(), 0);
		//更新project_progress表
		daoFit.getProgress_projectDao().insertRecord(new Progress_project(checkProject.getProjectId(),CalProgress_project.PROJECT_FINISH,"验收完成"));
		
	}

}
